package com.iuhao.web.test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by yanhao on 2017/11/11.
 */
public class ListFilter {
    /***
     * list 去重
     */

    public static void main(String[] args) {

        String a = "2";
        int b =2;
        if (a.equals(b)){
            System.out.println(a.equals(b)?"":"对");
        }



      /*  testHashSet();

        testHashSet1();
        double a= 20.0/100;
        int a1= 20/100;
        System.out.println(a+" : "+a1);
*/

    }

    private static void testHashSet1() {
        /**
         *HashSet实现了Set接口，它不允许集合中有重复的值，当我们提到HashSet时，第一件事情就是在将对象存储在HashSet之前，要先确保对象重写equals()和hashCode()方法
         */
        List<String> list  =   new  ArrayList<String>();
        list.add("aaa");
        list.add("bbb");
        list.add("aaa");
        list.add("aba");
        list.add("aaa");

       /* Set set = new  HashSet();
        List newList = new  ArrayList();
        set.addAll(list);*/
        List newList = new  ArrayList(new HashSet(list));

        System.out.println( "去重后的集合： " + newList);

    }

    private static void testHashSet() {
        List<String> list  =   new ArrayList<String>();

        list.add("aaa");
        list.add("bbb");
        list.add("aaa");
        list.add("aba");
        list.add("aaa");

        Set set = new HashSet();
        List newList = new  ArrayList();
        for (String cd:list) {
            if(set.add(cd)){
                newList.add(cd);
            }
        }
        System.out.println( "去重后的集合： " + newList);
    }


}
